﻿var ztShow=function(boxId,boxHeight,tabsId,tabsOn,times){

var getNodeList=function(nodeList){//获取标签下结点数
var New=[];var n=0;
for (var i=0;i<nodeList.length;++i ){if(nodeList[i].nodeType==1){n++;New.push(nodeList[i]);nodeList[i].setAttribute("num",n);}}
return New;
}

var $=function(id){return document.getElementById(id);}//定义ID查询器；
if($(tabsId).nodeType==1){var as=getNodeList($(tabsId).childNodes);}
var imgs=getNodeList($(boxId).childNodes);//取得轮换图片数组;
var tabsKey=true;//定义定时轮换KEY开关；
var tabsNum=0;//定义当前轮换数组位置坐标数；

if($(tabsId).nodeType==1){
for(var i=0;i<as.length;i++){
	as[i].onmouseover=function(){
		tabsKey=false;
		imgs[0].style.marginTop="-" + ((this.attributes["num"].nodeValue-1)*boxHeight) + "px";
		$(tabsOn).id="";this.id=tabsOn;
	}
	as[i].onmouseout=function(){
		tabsKey=true;
		tabsNum=this.attributes["num"].nodeValue-1;
	}
}
}

for(var i=0;i<imgs.length;i++){imgs[i].onmouseover=function(){tabsKey=false;}
	imgs[i].onmouseout=function(){tabsKey=true;}
}
if(times!=0){
this.setInterval(function(){
	if(tabsKey){
		if($(tabsId).nodeType==1){$(tabsOn).id="";as[tabsNum].id=tabsOn};
		imgs[0].style.marginTop="-" + ((tabsNum )*boxHeight) + "px";
		tabsNum++;
		if(tabsNum==imgs.length){tabsNum=0;}
	}
},times);
}
}
window.onload=function(){
ztShow("imgBox",430,"tabsBox","tabsOn",2000);
}